const http = require("http");
const app = require("./app");
const dotenv = require("dotenv");
const mongoose = require("mongoose");

dotenv.config({ path: "./config.env" });

const DB = process.env.DATABASE_URL.replace(
  "<password>",
  process.env.DATABASE_PASSWORD
);

const Local_DB = process.env.DATABASE_LOCAL_URL;
const Server_DB =
  "mongodb://hxadmin:snnu12345@47.251.12.254:27017/consult?authMechanism=DEFAULT&authSource=consult";
const mongoUri =
  // 'mongodb+srv://oldboy:LGNAWA8I2UAgutbZ@cluster0-ipcxx.mongodb.net/priceDB?retryWrites=true';
  "mongodb+srv://oldboy:LGNAWA8I2UAgutbZ@cluster0.ipcxx.mongodb.net/priceDB?retryWrites=true";

mongoose
  .connect(Server_DB, { useNewUrlParser: true, useUnifiedTopology: true })
  .then((con) => {
    console.log("连接成功！");
  })
  .catch((error) => {
    console.log("Altas Cluster connection error", error);
  });

const hostname = process.env.HOSTNAME;
const port = process.env.PORT;

const server = http.createServer(app);

app.listen(port, () => {
  console.log(`Server running at ${port}/`);
});
